package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.ReserveDAO;
import com.zerosky.crm.po.Reserve;
import com.zerosky.crm.service.ReserveService;
import com.zerosky.crm.util.PageInfo;

/**
 * Customer业务逻辑实现类
 * 
 * @author hugy;
 * @since 2017-06-08
 *
 */
@Service(value="reserveService")
public class ReserveServiceImpl implements ReserveService {

	@Autowired
	private ReserveDAO reserveDAO; // Customer数据接口

	/**
	 * 分页查询信息
	 */
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<Reserve> getReserveList(Map map) {
		PageInfo<Reserve> page = new PageInfo<Reserve>();
		int begin = (((int) map.get("page") - 1) * (int) map.get("pageSize"));

		// 写入数据
		map.put("pageNo", begin);
		List<Reserve> list = reserveDAO.getReserveList(map);
		page.setList(list);
		int count = reserveDAO.countReserve(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	@Override
	public Reserve getReserveById(String id) {
		return reserveDAO.getReserveById(id);
	}

	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public int addReserve(Reserve reserve) throws Exception {
		return reserveDAO.addReserve(reserve);
	}

	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public int updateReserve(Reserve reserve) throws Exception {
		return reserveDAO.updateReserve(reserve);
	}

	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public int deleteReserveById(String id) throws Exception {
		return reserveDAO.deleteReserveById(id);
	}

}
